home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / environ.doc < prev    next >
Encoding:
Text File  |  1984-10-18  |  2.5 KB  |  78 lines

  1. One if the most powerful features of BATch processing has gone too long
  2. undocumented.
  3.  
  4. The DOS Environment is accessible for use in BATs.
  5.  
  6. The standard keywords COMSPEC, PATH, PROMPT et al can all be read and set.
  7. New keywords can be set and checked within BATs.  The keywords are saved
  8. across BAT executions.
  9.  
  10. For instance BATs can check which screen is active using SET conventions
  11. as follows:
  12.  
  13.     . NOTE leading and trailing Percent signs
  14.     IF %SCREEN% == MONO GOTO COLOR
  15.     IF %SCREEN% == COLOR GOTO MONO
  16.     :COLOR
  17.     SET SCREEN=COLOR
  18.     . NOTE no spaces around '=' in SET
  19.     MODE CO80
  20.     EXIT
  21.     :MONO
  22.     SET SCREEN=MONO
  23.     MODE MONO
  24.     EXIT
  25.     . SCREEN is set and saved across BAT executions
  26.  
  27. Another example using a link convention allows BATs to call BATs:
  28.  
  29. *****CALL.BAT*****
  30.  
  31.     IF NOT %BATLABEL% == . GOTO %BATLABEL%
  32.     . note BATLABEL is assumed to be set to '.' as a null value
  33.     ECHO DO SOME STUFF HERE
  34.     SET BATCALR=%0
  35.     . give the called BAT my name to get back
  36.     . then leave word where to come back to
  37.     SET BATLABEL=RETURN
  38.     . set further parms to save %1 thru %9 if necessary
  39.     CALLED
  40.     :RETURN
  41.     ECHO FINISH UP HERE AFTER RETURN
  42.  
  43. *****CALLED.BAT*****
  44.  
  45.     ECHO DO STUFF WE WERE CALLED TO DO
  46.     . return to caller
  47.     %BATCALR%
  48.     . separate keywords will be necessary if further calls
  49.     . will be made
  50.  
  51. A note of caution (this is documented), the environment at boot time,
  52. is limited (I believe to only 128 bytes). If any resident modules are
  53. installed (i.e. PRINT, MODE, or GRAPHICS) the area cannot be expanded.
  54. You can SET enough variables from within AUTOEXEC.BAT to get enough
  55. space to get by.
  56.  
  57. I would also recommend setting up a set of conventions and preinitializing
  58. the parms you'll use to '.'; Null parameters are removed from the
  59. environment.
  60.  
  61. In summary -
  62. The rules are simple
  63.     SET a parm without percent signs
  64.     refer to them by enclosing them in percent signs
  65.  
  66. I hope this discovery will generate a lot of re-thinking some BAT
  67. techniques.
  68.  
  69.  
  70.                         Bob Becksted
  71.  
  72. s discovery will generate a lot of re-thinking some BAT
  73. techniques.
  74.  
  75.  
  76.                         Bob Becksted
  77.  
  78.